<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/5/4
 * Time: 20:45
 */

namespace app\storage\service\bom;
use app\storage\model\ReelsModel;
use service\excel\ExcelWrite;

class BatchBomService extends BaseBomService
{

    public function findReels($param)
    {
        $where = [
            'status' => 1,
            'reel_id' => ['like', $param['reel'] . '%'],
            'storage_uuid' => $param['storageUuid']
        ];
        $reelsModel = new ReelsModel();
        $result = $reelsModel->field('sub_materiel_id,reel_id,count,seat_code,container_code,time,DATEDIFF(now(),time) as day')
            ->where($where)->order('reel_id asc')
            ->select();
        return ret_template(true, '查询成功', $result);
    }


    public function downloadExcel(array $reels,$storageUuid){
        if (empty($reels)) {
            return ret_template(false, '没有勾选条码');
        }
        $where['reel_id'] = ['in',$reels];
        $where['storage_uuid'] = $storageUuid;
        $reelsModel = new ReelsModel();
        $reel = $reelsModel->field('sub_materiel_id,reel_id,count,seat_code,container_code,time,DATEDIFF(now(),time) as day')
            ->where($where)->order('reel_id asc')
            ->select()->toArray();
        $init = [
            'reel_id'=>'条码',
            'count'=>'数量',
            'seat_code'=>'站位',
            'container_code'=>'容器',
            'time'=>'时间',
            'day'=>'天数'
        ];
/*        if(count($result)>AppConstant::EXCEL_LENGTH){
            ExcelWrite::csvExport($result[0]['sub_materiel_id'].'批次出库',$init,$result);
        }else{*/
            $result = ExcelWrite::excelExport('批次出库',$init,$reel,true);
//        }
        return $result;
    }
}